

define(function(require,exports,module){

	function Main(jqObj,loadParams){
	
		var columns = [[
			{field:'userId',title:'主键',hidden:true},
			{field:'userOrgId',title:'外键',hidden:true},
			{field:'userOrgName',title:'所属部门',editor:{
				disabled:true
			}},
			{field:'userRoleName',title:'所属角色',editor:{
				required:true,
				eName:'combobox',
				name:'userRoleId',
				editable:false,
				valueField: 'roleId',
				textField: 'roleName',
				panelHeight:'auto',
				url:'sys/firerole/json.do'
			}},
			{field:'userName',title:'姓名',editor:{required:true}},
			{field:'userLoginName',title:'登录名',editor:{}},
			{field:'userSfzmhm',title:'身份证明号码',width:140,editor:{}},
			{field:'postName',title:'职务',editor:{
				eName:'combobox',
				name:'userPost',
				editable:false,
				valueField: 'codeValue',
				textField: 'codeName',
				panelHeight:'auto',
				queryParams:{codeType:4},
				url:'sys/firecode/json.do'
			}},
			{field:'policeRankName',title:'警衔',editor:{
				eName:'combobox',
				name:'userPoliceRank',
				editable:false,
				valueField: 'codeValue',
				textField: 'codeName',
				panelHeight:'auto',
				queryParams:{codeType:5},
				url:'sys/firecode/json.do'
			}},
			{field:'userBirthday',title:'生日',editor:{eName:'datebox'}},
			{field:'userTypeName',title:'类型',editor:{
				eName:'combobox',
				name:'userType',
				editable:false,
				panelHeight:'auto',
				data:[{value:'1',text:'现役'},{value:'2',text:'合同制'}]
			}},
			{field:'statusName',title:'状态 ',editor:{
				eName:'combobox',
				name:'userStatus',
				editable:false,
				panelHeight:'auto',
				data:[{value:'1',text:'正常'},{value:'0',text:'停用'}]
			}},
			{field:'remark',title:'备注',editor:{}},
			{field:'createDate',title:'创建时间'},
			{field:'lastLoginTime',title:'最后登录时间'}
		]];
		var formDialog = {
			title:'用户',
			formEx:{
				url:'sys/fireuser/save.do'
			}
		}
	
		var MainUI = {
			eName:'layoutExt',
			elements:[{
				region:'west',
				width:200,
				cssStyle:'overflow:auto',
				elements:{
					eName:'tree',
					dataType:'list',
					checkbox:false,
					lines:true,
					id:'orgId',
					pid:'orgParentId',
					nodeText:'orgShortName',
					url:'sys/fireorg/boxJson.do',
					onLoadSuccess:function(node,data){
						$(this).tree('select',$(this).tree('getRoot').target);
					},
					onSelect:function(node){
						jqGrid.datagrid('load',{userOrgId:node.id});
					}
				}
			},{
				region:'center',
				elements:{
					eName:'datagrid',
					idField:'userId',
					autoload:false,
					url:'sys/fireuser/json.do',
					delUrl:'sys/fireuser/del.do',
					columns:columns,
					formDialog:formDialog,
					toolbarEx:[null,{
						eName : 'linkbutton',
						text : '新增',
						uId : 'add',
						plain : true,
						iconCls : 'icon-add'
					}, {
						eName : 'linkbutton',
						text : '修改',
						uId : 'modify',
						plain : true,
						iconCls : 'icon-edit'
					}],
					onBeforeAdd:function(row){
						var node = jqTree.tree('getSelected');
						if(node == null){
							$ui.alert('请选择所属部门');	
							return;
						}
						row.userOrgId = node.orgId;
						row.userOrgName = node.orgShortName;
						row.userStatus = 1;
					}
				}
			}]
		}
		jqObj.createUI(MainUI);
		var jqGrid = jqObj.findJq('datagrid');
		var jqTree = jqObj.findJq('tree');
	}
	module.exports = Main;

});
